package com.zmn.plat.services.impl.channel.settle;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

import com.zmn.plat.model.entity.channel.settle.ChannelMergeSettle;
import com.zmn.plat.model.entity.channel.settle.ChannelMergeSettleQuery;
import com.zmn.plat.services.interfaces.channel.settle.ChannelMergeSettleService;
import com.zmn.plat.persistence.interfaces.channel.settle.ChannelMergeSettleDao;

/**
 * 描述: 渠道合并结算表基础接口实现类
 *
 * @author xujie
 * @since  2021-04-13 09:27:32
 **/
@Slf4j
@Service
public class ChannelMergeSettleServiceImpl implements ChannelMergeSettleService {

    private static final String TAG = "渠道合并结算表基础服务接口";

    @Resource
    private ChannelMergeSettleDao channelMergeSettleDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param channelId id
     * @author xujie
     * @since 2021-04-13 09:27:32
     **/
    @Override
    @ReadOnlyConnection
    public ChannelMergeSettle findById(Integer channelId) {

        Assert.notNull(channelId, TAG + "参数 channelId 不能为空");
        return channelMergeSettleDao.findById(channelId);
    }

    /**
     * 描述: 根据id列表查询合并标记
     *
     * @param channelIdList id 列表
     * @return List<String>
     * @author xujie
     * @since 2021-04-13
     **/
    @Override
    @ReadOnlyConnection
    public List<String> findMergeMarkByIdList(List<Integer> channelIdList) {

        if (channelIdList == null || channelIdList.size() == 0) {
            return new ArrayList<>();
        } else {
            return channelMergeSettleDao.findMergeMarkByIdList(channelIdList);
        }
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-04-13 09:27:32
     **/
    @Override
    @ReadOnlyConnection
    public List<ChannelMergeSettle> listPageByQuery(ChannelMergeSettleQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        query.setTotalCount(channelMergeSettleDao.countByQuery(query));
        return channelMergeSettleDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-04-13 09:27:32
     **/
    @Override
    @ReadOnlyConnection
    public List<ChannelMergeSettle> listByQuery(ChannelMergeSettleQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        return channelMergeSettleDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-04-13 09:27:32
     **/
    @Override
    @ReadOnlyConnection
    public Integer countByQuery(ChannelMergeSettleQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        return channelMergeSettleDao.countByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param channelMergeSettle 待修改数据
     * @return java.lang.Integer
     * @author xujie
     * @since 2021-04-13 09:27:32
     **/
    @Override
    public Integer updateByKey(ChannelMergeSettle channelMergeSettle) {

        Assert.notNull(channelMergeSettle, TAG + "参数 channelMergeSettle 不能为空");
        Assert.notNull(channelMergeSettle.getChannelId(), TAG + "字段 channelId 不能为空");
        return channelMergeSettleDao.updateByKey(channelMergeSettle);
    }

    /**
     * 描述: 批量修改数据
     * @param channelMergeSettleList 数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-04-13 09:27:32
     */
    @Override
    public Integer updateBatchByKey(List<ChannelMergeSettle> channelMergeSettleList) {

        if (channelMergeSettleList == null || channelMergeSettleList.size() == 0) {
            return null;
        }
        return channelMergeSettleDao.updateBatchByKey(channelMergeSettleList);
    }

    /**
     * 描述: 新增数据
     *
     * @param channelMergeSettle 待新增数据
     * @return java.lang.Integer 主键key
     * @author xujie
     * @since  2021-04-13 09:27:32
     **/
    @Override
    public Integer insert (ChannelMergeSettle channelMergeSettle) {

        Assert.notNull(channelMergeSettle, TAG + "参数 channelMergeSettle 不能为空");
        return channelMergeSettleDao.insert(channelMergeSettle);
    }

    /**
     * 描述: 批量新增数据
     * @param channelMergeSettleList 待新增数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-04-13 09:27:32
     */
    @Override
    public Integer insertBatch(List<ChannelMergeSettle> channelMergeSettleList) {

        if (channelMergeSettleList == null || channelMergeSettleList.size() == 0) {
            return null;
        }
        return channelMergeSettleDao.insertBatch(channelMergeSettleList);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param channelId 主键
     * @return 执行结果码
     * @author xujie
     * @since 2021-04-13 09:27:32
     */
    @Override
    public Integer deleteByKey(Integer channelId) {

        Assert.notNull(channelId, TAG + "参数 channelId 不能为空");
        return channelMergeSettleDao.deleteByKey(channelId);
    }

    /**
     * 描述: 根据主键批量删除数据
     *
     * @param channelIdList 待新增数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-04-13 09:27:32
     */
    @Override
    public Integer deleteBatchByKey(List<Integer> channelIdList) {

        if (channelIdList == null || channelIdList.size() == 0) {
            return null;
        }
        return channelMergeSettleDao.deleteBatchByKey(channelIdList);
    }

    @Override
    public void copy(Integer originalChannelId, int targetChannelId, String operator) {

        channelMergeSettleDao.copy(originalChannelId, targetChannelId, operator);
    }
}